package com.atcumt.shengce;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;


public class Main02 {

    public static void main(String[] args) throws IOException {
        // BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        // BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String s = in.nextLine();
            boolean flag = solve(s);
            if (flag) {
                long ip = converse(s);
                System.out.println(ip);
            } else {
                System.out.println(-1);
            }
        }
        in.close();
    }

    private static boolean solve(String str) {
        String[] split = str.split("\\.", -1);
        if (split.length != 7) {
            return false;
        }
        for (int i = 0; i < 7; i++) {
            if (i == 0 || i == 6) {
                if (i == 0 && split[i].equals("0")) {
                    return false;
                }
                if (split[i].equals("")) {
                    return false;
                }
            }
            if (split[i].length() > 3 || (split[i].length() > 1 && split[i].charAt(0) == '0')) {
                return false;
            }
            int sum = 0;
            for (char c : split[i].toCharArray()) {
                if (!Character.isDigit(c)) {
                    return false;
                }
                sum = sum * 10 + c - '0';
            }
            if (sum > 255) {
                return false;
            }
        }
        return true;
    }

    private static Long converse(String ip) {
        String[] split = ip.split("\\.");
        if (split == null || split.length != 7) {
            return null;
        }
        long ipNum;
        ipNum = (Long.valueOf(split[0]) << 48) + 
        (Long.valueOf(split[1]) << 40)+
        (Long.valueOf(split[2]) << 32)+
        (Long.valueOf(split[3]) << 24)+
        (Long.valueOf(split[4]) << 16)+
        (Long.valueOf(split[5]) << 8)+
        (Long.valueOf(split[6]));

        return ipNum;
    }
}
